package com.songlanyun.modules.order.controller.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.songlanyun.common.enums.BillConstant;
import com.songlanyun.common.enums.GoodsConstant;
import com.songlanyun.common.enums.UserBillConstant;
import com.songlanyun.common.utils.R;
import com.songlanyun.modules.gains.service.ShopOrderGainsService;
import com.songlanyun.modules.memberbill.service.SaleRefillCardBillService;
import com.songlanyun.modules.order.entity.ChildOrder;
import com.songlanyun.modules.order.service.ChildOrderService;
import com.songlanyun.modules.order.service.OrderService;
import com.songlanyun.modules.schedule.OrderScheduleServiceImpl;
import com.songlanyun.modules.usergains.entity.UserOrderGains;
import com.songlanyun.modules.usergains.service.UserBillService;
import com.songlanyun.modules.usergains.service.UserOrderGainsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("api/test")
public class Test {
    @Autowired
    ChildOrderService childOrderService;
    @Resource
    OrderScheduleServiceImpl orderScheduleService;
    @Autowired
    private ShopOrderGainsService shopOrderGainsService;
    @Autowired
    private OrderService orderService;
    @Autowired
    private UserOrderGainsService userOrderGainsService;
    @Autowired
    private UserBillService userBillService;
    @Autowired
    private SaleRefillCardBillService saleRefillCardBillService;


//    @GetMapping("/test")
    public R doJob (@RequestParam("shopId") Long shopId,@RequestParam("shopGainsId") Long shopGainsId){
//        List<UserOrderGains> list = userOrderGainsService.list(new LambdaQueryWrapper<UserOrderGains>()
//                .eq(UserOrderGains::getShopId, shopId)
//                .eq(UserOrderGains::getShopGainsId, shopGainsId)
//                .orderByAsc(UserOrderGains::getDistributionUserId)
//        );;
//        list.forEach(userOrderGains -> {
//            userOrderGains.setSettlement(true);
//            userOrderGains.setSettlementTime(new Date());
//            userOrderGains.setAbleSettlement(true);
//            userOrderGains.setShouldSettlementTime(new Date());
//            userOrderGains.setSettlementRemark("系统自动结算");
//            userOrderGainsService.modify(userOrderGains);
//            if (userOrderGains.getAbleGains().compareTo(BigDecimal.ZERO) > 0) {
//
//                userBillService.inBill(userOrderGains.getDistributionUserId(),
//                        userOrderGains.getEnvRemark(),
//                        UserBillConstant.InnerMode.FENRUN_INCOME,
//                        userOrderGains.getAbleGains(),
//                        userOrderGains.getOrderCode(),"系统");
//            }
//                saleRefillCardBillService.addBalance(userOrderGains.getDistributionUserId(),
//                        userOrderGains.getBalanceGains(),
//                        userOrderGains.getId().toString(),
//                        BillConstant.InnerMode.BALANCE_GAINS,
//                        BillConstant.InnerMode.BALANCE_GAINS.getMsg()+"之"+userOrderGains.getEnvRemark()
//                );
//        });
        return R.ok().put("data",shopId);
    }

}
